import React from 'react';
import { Button, Form, Input, InputNumber, Card, Row, Col } from 'antd';
import { useNavigate } from 'react-router-dom';

export default function PublicResourceCreate() {
  const [form] = Form.useForm();
  const navigate = useNavigate();

  const handleSave = async () => {
    try {
      const values = await form.validateFields();
      values.key = Date.now();
      navigate('/public-resource', { state: { newResource: values } });
    } catch (e) {}
  };

  return (
    <div style={{ background: '#f5f7fa', minHeight: '100vh', padding: 32 }}>
      <div style={{ maxWidth: 800, margin: '0 auto', background: '#fff', borderRadius: 8, boxShadow: '0 2px 8px rgba(0,0,0,0.04)', padding: 32, position: 'relative' }}>
        <h2 style={{ fontWeight: 700, fontSize: 22, marginBottom: 24 }}>公共资源新增页面</h2>
        <Form form={form} layout="vertical">
          <Card style={{ borderRadius: 12, marginBottom: 0, padding: 24 }} bodyStyle={{ padding: 0 }}>
            <Row gutter={32}>
              <Col span={12}>
                <Form.Item label="公共资源名称" name="name" rules={[{ required: true, message: '请输入公共资源名称' }]} required>
                  <Input placeholder="请输入公共资源名称" />
                </Form.Item>
                <Form.Item label="容纳人数" name="capacity" rules={[{ required: true, message: '请输入容纳人数' }]} required>
                  <InputNumber placeholder="请输入容纳人数" style={{ width: '100%' }} min={1} />
                </Form.Item>
                <Form.Item label="类型" name="type" rules={[{ required: true, message: '请输入类型' }]} required>
                  <Input placeholder="请输入类型" />
                </Form.Item>
                <Form.Item label="公共资源编号" name="code" rules={[{ required: true, message: '请输入公共资源编号' }]} required>
                  <Input placeholder="请输入公共资源编号" />
                </Form.Item>
              </Col>
              <Col span={12}>
                <Form.Item label="建筑面积（㎡）" name="area" rules={[{ required: true, message: '请输入建筑面积' }]} required>
                  <InputNumber placeholder="请输入建筑面积" style={{ width: '100%' }} min={0} />
                </Form.Item>
                <Form.Item label="出租单价（天）" name="price" rules={[{ required: true, message: '请输入出租单价' }]} required>
                  <InputNumber placeholder="请输入出租单价" style={{ width: '100%' }} min={0} />
                </Form.Item>
                <Form.Item label="标签" name="tag" rules={[{ required: true, message: '请输入标签' }]} required>
                  <Input placeholder="请输入标签" />
                </Form.Item>
              </Col>
            </Row>
          </Card>
        </Form>
        <div style={{ textAlign: 'center', marginTop: 40 }}>
          <Button type="primary" style={{ width: 120, marginRight: 32 }} onClick={handleSave}>保存</Button>
          <Button style={{ width: 120 }} onClick={() => navigate(-1)}>返回</Button>
        </div>
      </div>
    </div>
  );
} 